<template xmlns="http://www.w3.org/1999/html">
  <sea-dialog ref="dialog">
    <variable-log-list ref="variable_log" v-show="operation==='variable'"></variable-log-list>

    <channel-log-list ref="channel_log" v-show="operation==='channel'"></channel-log-list>

    <entry-log-list ref="entry_log" v-show="operation === 'entry'"></entry-log-list>

    <sea-code :text="text" v-show="operation === 'download'"></sea-code>
  </sea-dialog>
</template>

<script>
import VariableLogList from "./variable_log_list";
import ChannelLogList from "./channel_log_tree";
import EntryLogList from "./entry_log_list";

export default {
    components: {VariableLogList, ChannelLogList, EntryLogList}
    , props: {
        // 成功回调，通常是刷新数据表格
        onSucceed: {type: Function, default: undefined}
    }
    , data() {
        return {
            // 操作名称
            operation: undefined
            // 行级数据
            , row_data: undefined
            // 代码
            , text: undefined
        }
    }
    , methods: {
        /**
         * 操作栏事件分发
         * @param evt 事件
         * @param row 行级对象
         * @param old 可供回滚的参数
         */
        onAction: function (evt, row, old) {
            let jobId = row.idJob;
            this.operation = evt;
            this.row_id = jobId;
            if (evt === 'variable') {
                let dialog = {title: '输入参数', fullscreen: true};
                this.$refs.dialog.open(dialog).then(() => {
                    this.$refs.variable_log.reload(jobId);
                });
            } else if (evt === 'channel') {
                let dialog = {title: '通道日志', fullscreen: true};
                this.$refs.dialog.open(dialog).then(() => {
                    this.$refs.channel_log.reload(jobId);
                });
            } else if (evt === 'entry') {
                let dialog = {title: '日志明细', fullscreen: true};
                this.$refs.dialog.open(dialog).then(() => {
                    this.$refs.entry_log.reload(jobId);
                });
            } else if (evt === 'download') {
                let dialog = {title: '日志详情', fullscreen: true};
                this.$refs.dialog.open(dialog).then(() => {
                    this.$layers.ajax({
                        url: '/kettle/job/log/info'
                        , method: 'GET'
                        , params: {id: jobId}
                    }).then((ret) => {
                        if (ret.code === 0) {
                            this.text = ret.data.logField;
                        }
                    });
                });
            }
        }
    }
    //end
}
</script>
